package com.cskaoyan.shopping.converter;


import com.cskaoyan.shopping.dal.entitys.Item;
import com.cskaoyan.shopping.dto.CartProductDto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.springframework.stereotype.Component;

@Mapper(componentModel = "spring")
public interface CartItemConverter {



    @Mapping(source = "id", target = "productId")
    @Mapping(source = "title", target = "productName")
    @Mapping(source = "price", target = "salePrice")
    @Mapping(source = "imageBig", target = "productImg")
    @Mapping(target = "limitNum",
            expression = "java(        " +
                    "       item.getLimit_num()==null ?" +
                    "            Long.valueOf(item.getNum()) : " +
                    "            item.getLimit_num() < 0 && item.getNum() < 0 ?" +
                    "               10 : " + "Long.valueOf(item.getLimit_num())" +
                    "        )")
    CartProductDto item2Dto(Item item);
}
